package start.demo01.sort;

import org.junit.Test;

//排序算法
public class Sort {

    public void print(int[] list){
        for(int i=0;i<list.length;i++)
            System.out.print(list[i]+",");
    }
    @Test
    public void insertion() {
        int[] list = new int[]{3,5,2,4};
        for (int i = 1; i < list.length; i++) {
            int currentElement = list[i];//未排序的第一个元素，称为哨兵
            int j;
            for (j = i - 1; j >= 0 && currentElement < list[j]; j--)
                list[j + 1] = list[j];
            list[j + 1] = currentElement;
        }
        print(list);
    }


}
